package com.example.messagewall;

import com.example.messagewall.model.MessageInfo;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    List<MessageInfo> messageInfos = new ArrayList<>();

    /**
     * 发布留言
     */
    @RequestMapping("/publish")
    public Boolean publish(MessageInfo messageInfo) {
        //参数校验
        if(!StringUtils.hasLength(messageInfo.getFrom())
            || !StringUtils.hasLength(messageInfo.getTo())
            || !StringUtils.hasLength(messageInfo.getSay())) {
            return false;
        }
        //存留言
        messageInfos.add(messageInfo);
        return true;
    }
    /**
     * 获取留言
     */
    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageInfos;
    }
}
